package com.springapp.mvc;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.support.RequestContextUtils;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/")
public class HelloController {
	@RequestMapping(method = RequestMethod.GET)
	public String printWelcome(ModelMap model,HttpServletRequest request) {
		//父
		WebApplicationContext webApplicationContext_fa = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
		System.out.println("webApplicationContext id is "+webApplicationContext_fa.getId());
		System.out.println("webApplicationContext displayName is "+webApplicationContext_fa.getDisplayName());
		//子
		WebApplicationContext webApplicationContext  = RequestContextUtils.getWebApplicationContext(request);
		System.out.println("webApplicationContext id is "+webApplicationContext.getId());
		System.out.println("webApplicationContext displayName is "+webApplicationContext.getDisplayName());
		model.addAttribute("message", "Hello world!");
		return "hello";
	}
}